package com.itany.corejava.code08_常用类.泛型;

/**
 * @author 石小俊
 * @date 2023年05月04日 11:27
 */
public class User implements CompareInterface<User> {
    private String name;
    private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 比较用户姓名的长度
     * @param user
     * @return
     */
    @Override
    public int compareTo(User user) {
        if (this.getName().length() > user.getName().length()) {
            return 1;
        }
        if (this.getName().length() == user.getName().length()) {
            return 0;
        }
        return -1;
    }
}
